/*
 * Copyright (C) 2022 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

#include "kylintabletdekstopplugin.h"
#include <QtQml/qqml.h>
#include <QQmlContext>
#include <QQmlEngine>
#include <QDebug>
#include "modelmanager.h"
#include "appmanager.h"
#include "utils/getscreenshot.h"
#include "kgridview/kgridview.h"
//#include "KylinItemView/kquickgridview.h"
#include "base/launcheritem.h"
#include "base/categoryitem.h"
#include "core/modelmanager.h"
#include "core/appmanager.h"
#include "core/pluginitem.h"
#include "core/taskbarmanager.h"
#include "logger.h"
#include "utils/getscreenshot.h"
#include "utils/desktopbackground.h"
#include "ukui-log4qt.h"
#include "utils/generalsetting.h"
#include "utils/wirelessstatus.h"
#include "utils/wiredlinkstate.h"
#include "utils/accountlogout.h"
#include "utils/blurhelper.h"
#include "base/trayicon.h"
#include "base/sidebarstate.h"
#include "utils/taskbarmask.h"
#include "utils/showclendar.h"

void KylinTabletDekstopPlugin::registerTypes(const char *uri)
{
    Q_UNUSED(uri)
    qmlRegisterType<LauncherItem>("org.ukui.tablet", 1, 0, "LauncherItem");
    qmlRegisterType<CategoryItem>("org.ukui.tablet", 1, 0, "CategoryItem");
    qmlRegisterType<GetScreenShot>("org.ukui.tablet", 1, 0, "ScreenShot");
    qmlRegisterType<DesktopBackground>("org.ukui.tablet", 1, 0, "Background");
    qmlRegisterType<KQuickGridView>("org.ukui.tablet", 1, 0, "KGridView");
    qmlRegisterType<LauncherItem>("org.ukui.tablet", 1, 0, "LauncherItem");
    qmlRegisterType<CGeneralSetting>("MyGeneralSetting", 1, 0, "CGeneralSetting");
    qmlRegisterType<WirelessStatus>("org.ukui.tablet", 1, 0, "WirelessStatus");
    qmlRegisterType<WiredLinkState>("org.ukui.tablet", 1, 0, "WiredLinkState");
    qmlRegisterType<AccountLogout>("org.ukui.tablet", 1, 0, "AccountLogout");
    qmlRegisterType<BlurHelper>("org.ukui.tablet", 1, 0, "BlurHelper");
    qmlRegisterType<PluginItem>("org.ukui.tablet", 1, 0, "PluginItem");
    qmlRegisterType<TrayIcon>("org.ukui.tablet", 1, 0, "TrayIcon");
    qmlRegisterType<TaskbarMask>("org.ukui.tablet", 1, 0, "TaskbarMask");
}

void KylinTabletDekstopPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{
    Q_UNUSED(uri)
    ModelManager *modelManager = new ModelManager(this);
    engine->rootContext()->setContextProperty("modelManager", modelManager);

    AppManager *appMgr = new AppManager(this);
    engine->rootContext()->setContextProperty("appManager", appMgr);

    TrayIcon *trayIcon = new TrayIcon();
    engine->rootContext()->setContextProperty("trayIcon", trayIcon);

    SidebarState *sidebarState = new SidebarState(this);
    engine->rootContext()->setContextProperty("sidebarState", sidebarState);

    ShowClendar *showCal = new ShowClendar(this);
    engine->rootContext()->setContextProperty("showCal", showCal);

    QString qtquickSceneBackend = qEnvironmentVariable("QT_QUICK_BACKEND");
    bool openGLEnabled = qtquickSceneBackend == "software" ? false : true;
    engine->rootContext()->setContextProperty("openGLEnabled", QVariant::fromValue<bool>(openGLEnabled));
}
